import Cookies from 'js-cookie'

const TokenKey = 'Business-Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

// 授权在cookie对token的操作

export function getCookies(cname) {
  const name = cname + '='
  const ca = document.cookie.split(';')
  for (let i = 0; i < ca.length; i++) {
    const c = ca[i].trim()
    if (c.indexOf(name) === 0) return c.substring(name.length, c.length)
  }
  return ''
}

export function setCookies(cname, val, expires) {
  document.cookie = `${cname}=${val};expires=${expires}`
}

export function removeCookies(cname) {
  document.cookie = `${cname}=;expires=Thu, 01 Jan 1970 00:00:00 UTC;`
}
